package com.github.binarywang.demo.wechat.controller;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMaterialService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpMassNews;
import me.chanjar.weixin.mp.bean.material.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.InputStream;

/**
 * Created by DELL on 2018/2/27.
 */
@RestController
@RequestMapping("/media")
public class MediaController {

    @Autowired
    private WxMpService wxService;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public WxMediaUploadResult mediaUpload(String s, File file) throws WxErrorException {
        return null;
    }

    public WxMediaUploadResult mediaUpload(String s, String s1, InputStream inputStream) throws WxErrorException {
        return null;
    }

    public WxMediaImgUploadResult mediaImgUpload(File file) throws WxErrorException {
        return null;
    }

    @GetMapping("/addfile")
    public WxMpMaterialUploadResult materialFileUpload() throws WxErrorException {
        WxMpMaterial material = new WxMpMaterial("a",new File("D:\\test\\Desert.jpg")
                ,"","");
        WxMpMaterialUploadResult result = wxService.getMaterialService().materialFileUpload("image",material);
        logger.info(result.toString());
        return result;
    }

    @GetMapping("/addnews")
    public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews wxMpMaterialNews) throws WxErrorException {
        WxMpMaterialNews news = new WxMpMaterialNews();
        WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
        article.setTitle("title1");
        article.setThumbMediaId("13nDzVsOKhSZhosdIAU_jqpgIriXQfViMw14N1U4Wkk");
//        article.setAuthor("antball");
//        article.setDigest("摘要，仅有单图文消息才有摘要，多图文此处为空");
        article.setShowCoverPic(true);
        article.setContent("图文消息的具体内容，支持HTML标签，必须少于2万字符，小于1M，且此处会去除JS,涉及图片url必须来源 \"上传图文消息内的图片获取URL\"接口获取。外部图片url将被过滤。");
        article.setContentSourceUrl("http://www.baidu.com");
        news.addArticle(article);

        article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
        article.setTitle("title2");
        article.setThumbMediaId("13nDzVsOKhSZhosdIAU_jqpgIriXQfViMw14N1U4Wkk");
//        article.setAuthor("antball");
//        article.setDigest("摘要，仅有单图文消息才有摘要，多图文此处为空");
        article.setShowCoverPic(true);
        article.setContent("图文消息的具体内容，支持HTML标签，必须少于2万字符，小于1M，且此处会去除JS,涉及图片url必须来源 \"上传图文消息内的图片获取URL\"接口获取。外部图片url将被过滤。");
        article.setContentSourceUrl("http://www.baidu.com");
        news.addArticle(article);

        article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
        article.setTitle("title3");
        article.setThumbMediaId("13nDzVsOKhSZhosdIAU_jqpgIriXQfViMw14N1U4Wkk");
//        article.setAuthor("antball");
//        article.setDigest("摘要，仅有单图文消息才有摘要，多图文此处为空");
        article.setShowCoverPic(true);
        article.setContent("图文消息的具体内容，支持HTML标签，必须少于2万字符，小于1M，且此处会去除JS,涉及图片url必须来源 \"上传图文消息内的图片获取URL\"接口获取。外部图片url将被过滤。");
        article.setContentSourceUrl("http://www.baidu.com");
        news.addArticle(article);

        return wxService.getMaterialService().materialNewsUpload(news);
    }

    public File mediaDownload(String s) throws WxErrorException {
        return null;
    }

    public InputStream materialImageOrVoiceDownload(String s) throws WxErrorException {
        return null;
    }

    public WxMpMaterialVideoInfoResult materialVideoInfo(String s) throws WxErrorException {
        return null;
    }

    public WxMpMaterialNews materialNewsInfo(String s) throws WxErrorException {
        return null;
    }

    public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
        return false;
    }

    public boolean materialDelete(String s) throws WxErrorException {
        return false;
    }

    public WxMpMaterialCountResult materialCount() throws WxErrorException {
        return null;
    }

    public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int i, int i1) throws WxErrorException {
        return null;
    }

    public WxMpMaterialFileBatchGetResult materialFileBatchGet(String s, int i, int i1) throws WxErrorException {
        return null;
    }
}
